package com.gitee.xmhzzz.component.rocketmq.support;

import com.gitee.xmhzzz.component.rocketmq.context.TraceContext;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.MDC;

/**
 * @ClassName AopService
 * @Description
 * @Author wzq
 * @Date 2023/12/5 9:15
 * @Version 1.0
 */
@Aspect
public class RocketMQAsynTraceAopService {

    @Pointcut("execution(public * org.apache.rocketmq.spring.core.RocketMQTemplate.asyncSend*(..))")//切点表达式
    public void aspectPointcut()
    {

    }

    @Before(value = "aspectPointcut() && args(name,..)")
    public void before(String name){
        String traceId =  (String) MDC.get("X-B3-TraceId");
        String spanId =  (String) MDC.get("X-B3-SpanId");
        TraceContext.setTraceId(traceId);
        TraceContext.setSpanId(spanId);
    }

    @After(value = "aspectPointcut() && args(name,..)")
    public void after(String name){
        TraceContext.clear();
    }

}
